/*#include "lvgl/lvgl.h"
#include "lvgl/demos/lv_demos.h"
#include"gameset/game.h"
#include <unistd.h>
#include <pthread.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int board_state[15][15] = {{0}};
Gnode *global_list = NULL;
int main(void)
{
    //  1、设备初始化
    lv_init();

    /*Linux frame buffer device init
    lv_display_t * disp = lv_linux_fbdev_create();
    lv_linux_fbdev_set_file(disp, "/dev/fb0");
    lv_indev_t * indev = lv_evdev_create(LV_INDEV_TYPE_POINTER,"/dev/input/event0");
    
    //lv_style_set_text_font(&style_obj, & lv_mygec_font);
    
   /* int fd = open("./mplay.fifo",O_RDWR);       //   读写打开指定的有名管道
    if(fd == -1)
    {
        perror("open error");
        return -1;
    }
    
    int r = execlp("mplayer","mplayer","-slave","-quiet","-input","file=./mplay.fifo","-geometry","0:0","-zoom","-x","800","-y","480","ji.mp4",NULL);
    if(r == -1)
    {
        perror("execlp error");
        exit(-1);
    }
    //  2、主要操作 
    global_list=create_doublelist();
    lv_obj_t* screen = lv_scr_act();
    
    // 创建棋盘
    create_chessboard(screen);
    
    // 创建控制面板
    create_control_panel(screen);
    gamestart(screen);

   update_game_info(screen);

    //  3、检查事件链表是否有变化
    /*Handle LVGL tasks
    while(1) {
        lv_timer_handler();
        usleep(5000);
    }

    return 0;
}
*/
/*
#include "lvgl/lvgl.h"
#include "lvgl/demos/lv_demos.h"
#include "gameset/game.h"
#include <unistd.h>
#include <pthread.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>


int board_state[15][15] = {{0}};
Gnode *global_list = NULL;
lv_obj_t* screen;
int video_played = 0;

// 播放视频的函数
void play_video(const char* video_path) {
    pid_t pid = fork();
    if (pid == 0) {
        // 子进程播放视频
        execlp("mplayer", "mplayer", "-fs", "-quiet", video_path, NULL);
        perror("execlp failed");
        exit(1);
    } else if (pid > 0) {
        // 父进程等待视频播放完成
        int status;
        waitpid(pid, &status, 0);
        video_played = 1;
    } else {
        perror("fork failed");
    }
}

// 视频播放线程
void* video_thread(void* arg) {
    play_video("ji.mp4"); // 替换为你的视频路径
    return NULL;
}

// 视频播放完成后创建游戏界面
void create_game_interface() {
    global_list = create_doublelist();
    screen = lv_scr_act();
    
    // 创建棋盘
    create_chessboard(screen);
    
    // 创建控制面板
    create_control_panel(screen);
    
    // 创建开始界面
    gamestart(screen);
    update_game_info();
}

int main(void) {
    // 1. 初始化LVGL
    lv_init();

    // 2. 创建显示设备
    lv_display_t * disp = lv_linux_fbdev_create();
    lv_linux_fbdev_set_file(disp, "/dev/fb0");
    
    // 3. 创建输入设备
    lv_indev_t * indev = lv_evdev_create(LV_INDEV_TYPE_POINTER, "/dev/input/event0");
    
    // 4. 创建视频播放线程
    pthread_t tid;
    if (pthread_create(&tid, NULL, video_thread, NULL) != 0) {
        perror("Failed to create video thread");
        // 如果创建线程失败，直接进入游戏界面
        create_game_interface();
    } else {
        // 等待视频播放线程完成
        pthread_join(tid, NULL);
        // 视频播放完成后创建游戏界面
        create_game_interface();
    }

    // 5. LVGL主循环
    while (1) {
        lv_timer_handler();
        usleep(5000);
    }

    return 0;
}*/

/*
#include "lvgl/lvgl.h"
#include "lvgl/demos/lv_demos.h"
#include "gameset/game.h"
#include <unistd.h>
#include <pthread.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>


int board_state[15][15] = {{0}};
Gnode *global_list = NULL;
lv_obj_t* screen;






// 视频播放完成后创建游戏界面
void create_game_interface() {
    global_list = create_doublelist();
    screen = lv_scr_act();
    
    // 创建棋盘
    create_chessboard(screen);
    
    // 创建控制面板
    create_control_panel(screen);
    
    // 创建开始界面
    //gamestart(screen);
    update_game_info();
}

int main(void) {
    // 1. 初始化LVGL
    lv_init();

    // 2. 创建显示设备
    lv_display_t * disp = lv_linux_fbdev_create();
    lv_linux_fbdev_set_file(disp, "/dev/fb0");
    
    // 3. 创建输入设备
    lv_indev_t * indev = lv_evdev_create(LV_INDEV_TYPE_POINTER, "/dev/input/event0");
    
    create_game_interface();

    // 5. LVGL主循环
    while (1) {
        lv_timer_handler();
        usleep(5000);
    }

    return 0;
}
*/

#include "lvgl/lvgl.h"
#include "gameset/game.h"
#include <unistd.h>
#include <pthread.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>

// 全局变量
Gnode *global_list = NULL;
lv_obj_t *screen;
int board_state[15][15] = {{0}};

int main(void) {
    // 1. 初始化LVGL
     lv_init();

    // 2. 创建显示设备
    lv_display_t * disp = lv_linux_fbdev_create();
    lv_linux_fbdev_set_file(disp, "/dev/fb0");
    
    // 3. 创建输入设备
    lv_indev_t * indev = lv_evdev_create(LV_INDEV_TYPE_POINTER, "/dev/input/event0");
    
   global_list = create_doublelist();
    if (global_list == NULL) {
        printf("无法创建双向链表\n");

    }

    screen = lv_scr_act();

    // 创建棋盘
    create_chessboard(screen);

    // 创建控制面板
    create_control_panel(screen);

    // 更新游戏信息
    update_game_info();

    // 5. LVGL主循环
    while (1) {
        lv_timer_handler();
        usleep(5000); // 5ms 延迟，您可以根据需要调整
    }

    // 6. 清理资源 (通常不会执行到这里)
    if (global_list) {
        Node *current = global_list->first;
        while (current != NULL) {
            Node *next = current->next;
            free(current);
            current = next;
        }
        free(global_list);
    }



    return 0;
}

 
